package com.abo.yaas.view.widgets;

import com.abo.yaas.i18n.Lang;
import com.abo.yaas.i18n.LocaleChangeListener;
import com.abo.yaas.i18n.LocaleChangedEvent;
import com.vaadin.ui.Button;

@SuppressWarnings("serial")
public class LocaleSensitiveButton extends Button implements LocaleChangeListener {

    private String translationId = "";

    public LocaleSensitiveButton(String translationId) {
        super(Lang.getMessage(translationId));
        this.translationId = translationId;
        Lang.addListener(this);
    }

    public LocaleSensitiveButton(String translationId, Object target, String methodName) {
        super(Lang.getMessage(translationId), target, methodName);
        this.translationId = translationId;
        Lang.addListener(this);
    }

    @Override
    public Class<?> getType() {
        return super.getType();
    }

    @Override
    public void localeChanged(LocaleChangedEvent event) {
        setCaption(Lang.getMessage(translationId));
    }
}
